package com.cloudbroker.bcs.csvc.push.facade.service;

import cn.jpush.api.JPushClient;
import cn.jpush.api.common.resp.APIConnectionException;
import cn.jpush.api.common.resp.APIRequestException;
import cn.jpush.api.common.resp.DefaultResult;
import cn.jpush.api.device.TagAliasResult;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.report.ReceivedsResult;
import cn.jpush.api.schedule.ScheduleResult;
import com.cloudbroker.bcs.common.entity.HSBCPSBackVO;
import com.cloudbroker.bcs.common.util.VOUtil;
import com.cloudbroker.bcs.csvc.push.api.service.PushFacadeService;
import com.cloudbroker.bcs.csvc.push.api.vo.request.*;
import com.cloudbroker.bcs.csvc.push.api.vo.response.PushBack;
import com.cloudbroker.bcs.csvc.push.api.vo.response.PushReportBack;
import com.cloudbroker.bcs.csvc.push.api.vo.response.PushReportData;
import com.cloudbroker.bcs.csvc.push.api.vo.response.TagAliasBack;
import com.cloudbroker.bcs.csvc.push.facade.exception.CommonException;
import com.cloudbroker.bcs.csvc.push.facade.util.ClientConstant;
import com.cloudbroker.bcs.csvc.push.facade.util.ParamConstants;
import com.cloudbroker.bcs.csvc.push.facade.util.PushUtil;
import com.cloudbroker.bcs.platform.ltb.bizapi.constants.HSBCPSErrorCodes;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.*;


/**
 * Created by daibd19671 on 2016/9/9.
 */
@Service
public class PushFacadeServiceFacade implements PushFacadeService {

    public JPushClient jpushClient;
    public PushUtil pushUtil;
    protected static final Logger log = LoggerFactory.getLogger(PushFacadeServiceFacade.class);

    @Override
    public TagAliasBack getDeviceTagAlias(DeviceTagAliasVo deviceTagAliasVo) {
        jpushClient = ClientConstant.getClient(deviceTagAliasVo.getApp_key(), deviceTagAliasVo.getApp_secret());
        TagAliasResult tagResult = null;
        try {
            tagResult = jpushClient.getDeviceTagAlias(deviceTagAliasVo.getRegistration_id());
        } catch (APIConnectionException e) {
            log.error("无法连接推送服务器，请稍后重试：", e);
        } catch (APIRequestException e) {
            log.error("极光服务器处理请求失败：", e);
            log.error("HTTP Status: " + e.getStatus());
            log.error("Error Code: " + e.getErrorCode());
            log.error("Error Message: " + e.getErrorMessage());
            log.error("msg ID: " + e.getMsgId());
            return VOUtil.genErrorResult(String.valueOf(e.getErrorCode()),e.getErrorMessage(),
                    TagAliasBack.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (tagResult != null && tagResult.isResultOK()) {
            TagAliasBack back = new TagAliasBack();
            back.setAlias(tagResult.alias);
            StringBuilder sb = new StringBuilder();
            int i = 0;
            for (String str : tagResult.tags) {
                sb.append(str);
                if (i != tagResult.tags.size()) {
                    sb.append(",");
                }
            }
            back.setTags(sb.toString());
            return VOUtil.setSuccessResult(back);
        } else {
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.GET_DEVICE_TAG_ALIAS_ERR,
                    TagAliasBack.class);
        }
    }

    private Set<String> stringToSet(String str){
        Set<String> set = new HashSet<>();
        String[] strs = str.split(",");
        for(String s : strs){
            if(StringUtils.isNotEmpty(s)){
                set.add(s);
            }
        }
        return set;
    }
    @Override
    public HSBCPSBackVO updateDeviceTagAlias(UpdateDeviceTagAliasVo updateDeviceTagAliasVo) {
        jpushClient = ClientConstant.getClient(updateDeviceTagAliasVo.getApp_key(), updateDeviceTagAliasVo.getApp_secret());
        DefaultResult defaultResult = null;
        try {
            defaultResult = jpushClient.updateDeviceTagAlias(updateDeviceTagAliasVo.getRegistration_id(),
                    updateDeviceTagAliasVo.getAlias_name(),
                    this.stringToSet(updateDeviceTagAliasVo.getTags_add()),this.stringToSet(updateDeviceTagAliasVo.getTags_remove()));
        } catch (APIConnectionException e) {
            log.error("无法连接推送服务器，请稍后重试：", e);
        } catch (APIRequestException e) {
            log.error("极光服务器处理请求失败：", e);
            log.error("HTTP Status: " + e.getStatus());
            log.error("Error Code: " + e.getErrorCode());
            log.error("Error Message: " + e.getErrorMessage());
            log.error("msg ID: " + e.getMsgId());
            return VOUtil.genErrorResult(String.valueOf(e.getErrorCode()),e.getErrorMessage(),
                    HSBCPSBackVO.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(defaultResult!=null && defaultResult.isResultOK()){
            return VOUtil.setSuccessResult(new HSBCPSBackVO());
        }else{
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.UPDATE_TAG_ALIAS_ERR,
                    HSBCPSBackVO.class);
        }
    }

    @Override
    public HSBCPSBackVO addRemoveDevicesFromTag(AddRemoveTagVo addRemoveTagVo) {
        jpushClient = ClientConstant.getClient(addRemoveTagVo.getApp_key(), addRemoveTagVo.getApp_secret());
        DefaultResult result = null;
        try {
            Set<String> tagSet = new HashSet<>();
            Set<String> userAddSet = new HashSet<>();
            Set<String> userRemoveSet = new HashSet<>();
            tagSet.add(addRemoveTagVo.getTag());
            userAddSet.add(addRemoveTagVo.getAddRegIds());
            userRemoveSet.add(addRemoveTagVo.getRemoveRegIds());
            result = jpushClient.addRemoveDevicesFromTag(addRemoveTagVo.getTag(), userAddSet, userRemoveSet);
        } catch (APIConnectionException e) {
            log.error("无法连接推送服务器，请稍后重试：", e);
        } catch (APIRequestException e) {
            log.error("请求处理失败：", e);
            return VOUtil.genErrorResult(String.valueOf(e.getErrorCode()), e.getErrorMessage(),
                    HSBCPSBackVO.class);
        }
        if (result != null && result.isResultOK()) {
            return VOUtil.setSuccessResult(new HSBCPSBackVO());
        } else {
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.UPDATE_TAG_ALIAS_ERR,
                    HSBCPSBackVO.class);
        }
    }

    @Override
    public PushBack sendAllNotificationWithTag(PushTagVo pushTagVo) {
        pushUtil = new PushUtil(pushTagVo.getApp_secret(),pushTagVo.getApp_key());
        PushBack back = new PushBack();
        try {
            if(pushTagVo.getPush_time()==null || pushTagVo.getPush_time()==0L) {
                PushResult psRes = pushUtil.sendAllNotificationWithTag(
                        pushTagVo.getMessage_title(),
                        pushTagVo.getContent(), pushTagVo.getTag());
                if(psRes!=null && psRes.isResultOK()){
                    back.setMsg_id(String.valueOf(psRes.msg_id));
                    back.setSendno(psRes.sendno);
                    return VOUtil.setSuccessResult(back);
                }
            }else{
                if(System.currentTimeMillis() >= pushTagVo.getPush_time()){
                    return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_TIME_ERR,PushBack.class);
                }
                ScheduleResult scRes = pushUtil.schedulePushByTag(
                        pushTagVo.getMessage_title(),
                        pushTagVo.getContent(),
                        pushTagVo.getTag(),
                        pushTagVo.getPush_time());
                if(scRes!=null && scRes.isResultOK()){
                    back.setMsg_id(scRes.getSchedule_id());
                    return VOUtil.setSuccessResult(back);
                }
            }
        } catch (APIConnectionException e) {
            log.error("无法连接推送服务器，请稍后重试. ", e);
        } catch (APIRequestException e) {
            log.error("Error response from JPush server. Should review and fix it. ", e);
            return VOUtil.genErrorResult(String.valueOf(e.getErrorCode()),e.getErrorMessage(),
                    PushBack.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_ERR,
                PushBack.class);
    }

    @Override
    public PushBack sendAllNotificationWithAlias(PushAliasVo pushAliasVo) {
        pushUtil = new PushUtil(pushAliasVo.getApp_secret(),pushAliasVo.getApp_key());
        try {
            if(pushAliasVo.getPush_time()==null || pushAliasVo.getPush_time()==0L) {
                PushResult psRes = pushUtil.sendAllNotificationWithAlias(
                        pushAliasVo.getMessage_title(),
                        pushAliasVo.getContent(), null,
                        pushAliasVo.getAlias_name());
                if (psRes != null && psRes.isResultOK()) {
                    PushBack back = new PushBack();
                    back.setMsg_id(String.valueOf(psRes.msg_id));
                    back.setSendno(psRes.sendno);
                    return VOUtil.setSuccessResult(back);
                }
            }else{
                if(System.currentTimeMillis() >= pushAliasVo.getPush_time()){
                    return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_TIME_ERR,PushBack.class);
                }
                ScheduleResult scpsRes = pushUtil.schedulePushByAlias(
                        pushAliasVo.getMessage_title(),
                        pushAliasVo.getContent(),
                        pushAliasVo.getAlias_name(),
                        pushAliasVo.getPush_time());
                if (scpsRes != null && scpsRes.isResultOK()) {
                    PushBack back = new PushBack();
                    back.setMsg_id(scpsRes.getSchedule_id());
                    return VOUtil.setSuccessResult(back);
                }
            }
        } catch (APIConnectionException e) {
            log.error("无法连接推送服务器，请稍后重试. ", e);
        } catch (APIRequestException e) {
            log.error("Error response from JPush server. Should review and fix it. ", e);
            return VOUtil.genErrorResult(String.valueOf(e.getErrorCode()),e.getErrorMessage(),
                    PushBack.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_ERR,
                PushBack.class);
    }

    @Override
    public PushBack sendAllNotificationWithRegId(PushRegIdVo pushRegIdVo) {
        pushUtil = new PushUtil(pushRegIdVo.getApp_secret(),pushRegIdVo.getApp_key());
        try {
            if(pushRegIdVo.getPush_time()==null || pushRegIdVo.getPush_time()==0L) {
                PushResult psRes = pushUtil.sendAllNotificationWithRegId(
                        pushRegIdVo.getMessage_title(),
                        pushRegIdVo.getContent(), null,
                        pushRegIdVo.getRegistration_id());
                if(psRes!=null && psRes.isResultOK()){
                    PushBack back = new PushBack();
                    back.setMsg_id(String.valueOf(psRes.msg_id));
                    back.setSendno(psRes.sendno);
                    return VOUtil.setSuccessResult(back);
                }
            }else{
                if(System.currentTimeMillis() >= pushRegIdVo.getPush_time()){
                    return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_TIME_ERR,PushBack.class);
                }
                ScheduleResult scpsRes = pushUtil.schedulePushByRegID(
                        pushRegIdVo.getMessage_title(),
                        pushRegIdVo.getContent(),
                        pushRegIdVo.getRegistration_id(),
                        pushRegIdVo.getPush_time());
                if(scpsRes!=null && scpsRes.isResultOK()){
                    PushBack back = new PushBack();
                    back.setMsg_id(scpsRes.getSchedule_id());
                    return VOUtil.setSuccessResult(back);
                }
            }
        } catch (APIConnectionException e) {
            log.error("无法连接推送服务器，请稍后重试. ", e);
        } catch (APIRequestException e) {
            log.error("Error response from JPush server. Should review and fix it. ", e);
            return VOUtil.genErrorResult(String.valueOf(e.getErrorCode()),e.getErrorMessage(),
                    PushBack.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_ERR,
                PushBack.class);
    }

    @Override
    public PushBack sendNotificationAll(PushAllVo pushAllVo) {
        pushUtil = new PushUtil(pushAllVo.getApp_secret(),pushAllVo.getApp_key());
        try {
            if(pushAllVo.getPush_time()==null || pushAllVo.getPush_time()==0L) {
                PushResult psRes = pushUtil.sendNotificationAll(
                        pushAllVo.getMessage_title(),
                        pushAllVo.getContent());
                if(psRes!=null && psRes.isResultOK()){
                    PushBack back = new PushBack();
                    back.setMsg_id(String.valueOf(psRes.msg_id));
                    back.setSendno(psRes.sendno);
                    return VOUtil.setSuccessResult(back);
                }
            }else{
                if(System.currentTimeMillis() >= pushAllVo.getPush_time()){
                    return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_TIME_ERR,PushBack.class);
                }
                ScheduleResult scpsRes = pushUtil.schedulePushByALL(
                        pushAllVo.getMessage_title(),
                        pushAllVo.getContent(),
                        pushAllVo.getPush_time());
                if(scpsRes!=null && scpsRes.isResultOK()){
                    PushBack back = new PushBack();
                    back.setMsg_id(scpsRes.getSchedule_id());
                    return VOUtil.setSuccessResult(back);
                }
            }
        } catch (APIConnectionException e) {
            log.error("无法连接推送服务器，请稍后重试. ", e);
        } catch (APIRequestException e) {
            log.error("Error response from JPush server. Should review and fix it. ", e);
            log.error(e.getErrorCode()+" : "+e.getErrorMessage());
            return VOUtil.genErrorResult(String.valueOf(e.getErrorCode()),e.getErrorMessage(),
                    PushBack.class);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("推送消息未知错误",e);
        }
        return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_ERR,
                    PushBack.class);
    }



    @Override
    public HSBCPSBackVO enableSchedulePush(EnableDisableScheduleVo deleteScheduleVo){
        jpushClient = ClientConstant.getClient(deleteScheduleVo.getApp_key(), deleteScheduleVo.getApp_secret());
        try {
            jpushClient.enableSchedule(deleteScheduleVo.getScheduleId());
        } catch (APIConnectionException e) {
            e.printStackTrace();
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_CONN_ERR,HSBCPSBackVO.class);
        } catch (APIRequestException e) {
            e.printStackTrace();
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_CONN_ERR,HSBCPSBackVO.class);
        } catch (Exception e){
            e.printStackTrace();
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_CONN_ERR,HSBCPSBackVO.class);
        }
        return VOUtil.setSuccessResult(new HSBCPSBackVO());
    }

    @Override
    public HSBCPSBackVO disableSchedulePush(EnableDisableScheduleVo deleteScheduleVo){
        jpushClient = ClientConstant.getClient(deleteScheduleVo.getApp_key(), deleteScheduleVo.getApp_secret());
        try {
            jpushClient.disableSchedule(deleteScheduleVo.getScheduleId());
        } catch (APIConnectionException e) {
            e.printStackTrace();
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_CONN_ERR,HSBCPSBackVO.class);
        } catch (APIRequestException e) {
            e.printStackTrace();
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_CONN_ERR,HSBCPSBackVO.class);
        } catch (Exception e){
            e.printStackTrace();
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_CONN_ERR,HSBCPSBackVO.class);
        }
        return VOUtil.setSuccessResult(new HSBCPSBackVO());
    }


    @Override
    public HSBCPSBackVO updateSchedulePush(UpdateScheduleVo updateScheduleVo){
        pushUtil = new PushUtil(updateScheduleVo.getApp_secret(),updateScheduleVo.getApp_key());
        ScheduleResult scheduleResult = null;
        try {
            scheduleResult = pushUtil.updateSchedulePush(updateScheduleVo.getScheduleId(),updateScheduleVo.getPush_type(),
                    updateScheduleVo.getAlias_name(),updateScheduleVo.getRegistration_id(),updateScheduleVo.getTag(),
                    updateScheduleVo.getPush_time(),updateScheduleVo.getMessage_title(),updateScheduleVo.getContent());
        } catch (APIConnectionException e) {
            e.printStackTrace();
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_CONN_ERR,HSBCPSBackVO.class);
        } catch (APIRequestException e) {
            e.printStackTrace();
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_CONN_ERR,HSBCPSBackVO.class);
        } catch (Exception e){
            e.printStackTrace();
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_CONN_ERR,HSBCPSBackVO.class);
        }
        if(scheduleResult != null && scheduleResult.isResultOK()){
            return VOUtil.setSuccessResult(new HSBCPSBackVO());
        }else{
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_SCHEDULE_UPDATE_ERR,
                    PushBack.class);
        }
    }


//    @Override
//    public HSBCPSBackVO createSingleSchedule(SchedulePushVo schedulePushVo) {
//        jpushClient = ClientConstant.getClient(schedulePushVo.getApp_key(), schedulePushVo.getApp_secret());
//        String name = "test_schedule_example";
//        String time = "2016-09-29 12:30:25";
//        PushPayload push = PushPayload.alertAll("test schedule example.");
//        ScheduleResult result = null;
//        try {
//            result = jpushClient.createSingleSchedule(name, time, push);
//        } catch (APIConnectionException e) {
//            e.printStackTrace();
//        } catch (APIRequestException e) {
//            e.printStackTrace();
//        }
//        if(result!=null && result.isResultOK()){
//            return VOUtil.setSuccessResult(new HSBCPSBackVO());
//        }else {
//            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_ERR,
//                    HSBCPSBackVO.class);
//        }
//    }



    public PushBack sendSingleSchedulePushByRegID(SingleSchedulePushRegIDVo schedulePushRegIDVo){
        ScheduleResult scpsRes = null;
        try {
            scpsRes = pushUtil.schedulePushByRegID(
                    schedulePushRegIDVo.getMessage_title(),
                    schedulePushRegIDVo.getContent(),
                    schedulePushRegIDVo.getRegistration_id(),
                    schedulePushRegIDVo.getPush_time());
        } catch (APIConnectionException e) {
            e.printStackTrace();
        } catch (APIRequestException e) {
            e.printStackTrace();
        } catch (Exception e){
            e.printStackTrace();
        }
        if(scpsRes!=null && scpsRes.isResultOK()){
            return VOUtil.setSuccessResult(new PushBack());
        }else{
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_SCHEDULE_ERR,PushBack.class);
        }
    }
    public PushBack sendSingleSchedulePushByTag(SingleSchedulePushTagVo schedulePushTagVo){
        ScheduleResult scpsRes = null;
        try {
            scpsRes = pushUtil.schedulePushByTag(
                    schedulePushTagVo.getMessage_title(),
                    schedulePushTagVo.getContent(),
                    schedulePushTagVo.getTag(),
                    schedulePushTagVo.getPush_time());
        } catch (APIConnectionException e) {
            e.printStackTrace();
        } catch (APIRequestException e) {
            e.printStackTrace();
        } catch (Exception e){
            e.printStackTrace();
        }
        if(scpsRes!=null && scpsRes.isResultOK()){
            return VOUtil.setSuccessResult(new PushBack());
        }else{
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_SCHEDULE_ERR,PushBack.class);
        }
    }


    public PushBack sendSingleSchedulePushByAlias(SingleSchedulePushAliasVo singleSchedulePushAliasVo) {
        pushUtil = new PushUtil(singleSchedulePushAliasVo.getApp_secret(),singleSchedulePushAliasVo.getApp_key());
        ScheduleResult scpsRes = null;
        try {
            scpsRes = pushUtil.schedulePushByAlias(
                    singleSchedulePushAliasVo.getMessage_title(),
                    singleSchedulePushAliasVo.getContent(),
                    singleSchedulePushAliasVo.getAlias_name(),
                    singleSchedulePushAliasVo.getPush_time());
        } catch (APIConnectionException e) {
            log.error("无法连接推送服务器，请稍后重试. ", e);
        } catch (APIRequestException e) {
            log.error("Error response from JPush server. Should review and fix it. ", e);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(scpsRes!=null && scpsRes.isResultOK()){
            return VOUtil.setSuccessResult(new PushBack());
        }else{
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_ERR,
                    PushBack.class);
        }
    }

    public PushBack sendSingleSchedulePushAll(SingleSchedulePushAllVo singleSchedulePushAllVo) {
        pushUtil = new PushUtil(singleSchedulePushAllVo.getApp_secret(),singleSchedulePushAllVo.getApp_key());
        ScheduleResult scpsRes = null;
        try {
            scpsRes = pushUtil.schedulePushByALL(
                    singleSchedulePushAllVo.getMessage_title(),
                    singleSchedulePushAllVo.getContent(),
                    singleSchedulePushAllVo.getPush_time());
        } catch (APIConnectionException e) {
            log.error("无法连接推送服务器，请稍后重试. ", e);
        } catch (APIRequestException e) {
            log.error("Error response from JPush server. Should review and fix it. ", e);
            log.error(e.getErrorCode()+" : "+e.getErrorMessage());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("推送消息未知错误",e);
        }
        if(scpsRes!=null && scpsRes.isResultOK()){
            return VOUtil.setSuccessResult(new PushBack());
        }else{
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_SCHEDULE_UPDATE_ERR,
                    PushBack.class);
        }
    }


    @Override
    public PushReportBack getPushReport(PushReportVo pushReportVo){
        pushUtil = new PushUtil(pushReportVo.getApp_secret(),pushReportVo.getApp_key());
        String[] msg_id = pushReportVo.getMsg_ids().split(",");
        ReceivedsResult result = null;
        try {
            result = pushUtil.pushReport(msg_id);
        } catch (APIConnectionException e) {
            e.printStackTrace();
        } catch (APIRequestException e) {
            e.printStackTrace();
        }
        if(result.isResultOK()){
            List<ReceivedsResult.Received>  list = result.received_list;
            List<PushReportData> backList = new ArrayList<>(list.size());
            for(ReceivedsResult.Received received : list){
                PushReportData data = new PushReportData();
                data.setMsg_id(received.msg_id);
                data.setAndroid_received(received.android_received);
                data.setIos_apns_sent(received.ios_apns_sent);
                data.setIos_msg_received(received.ios_msg_received);
                data.setWp_mpns_sent(received.wp_mpns_sent);
                backList.add(data);
            }
            PushReportBack back = new PushReportBack();
            back.setData_list(backList);
            return VOUtil.setSuccessResult(back);
        }else{
            return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_REPORT_ERR,PushReportBack.class);
        }
    }
}
